package com.hbean.service.impl;

import com.github.pagehelper.PageHelper;
import com.hbean.entity.SysLog;
import com.hbean.mapper.SysLogMapper;
import com.hbean.service.SysLogService;
import com.hbean.system.config.SysCache;
import com.hbean.utils.Condition;
import com.hbean.utils.HUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: null
 * @Project: hbean
 * @Author: hjibo
 * @CreateDate: 2018-10-28 22:33
 * @ModificationHistory:
 */

@Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogMapper sysLogMapper;
    @Autowired
    private SysCache sysCache;


    @Override
    public boolean insertData(SysLog sysLog) {
        sysLog.setSl00(HUtil.uuidOf18());


        return this.sysLogMapper.insertData(sysLog);
    }

    @Override
    public boolean deleteData(String str) {
        return false;
    }

    @Override
    public boolean updateData(SysLog sysLog) {
        return false;
    }

    @Override
    public List<SysLog> getDatas(Condition condition) {

        int pageIndex = condition.getParam11() == null ? 0 : Integer.parseInt(condition.getParam11());
        int pageSize = condition.getParam12() == null ? 0 : Integer.parseInt(condition.getParam12());
        PageHelper.startPage(pageIndex, pageSize);

        condition.setParam2(HUtil.stringToDateStr(condition.getParam2(),"yyyy-MM-dd HH:mm:ss","yyyyMMddHHmmss"));
        condition.setParam3(HUtil.stringToDateStr(condition.getParam3(),"yyyy-MM-dd HH:mm:ss","yyyyMMddHHmmss"));
        List<SysLog> sysLogs = this.sysLogMapper.selectDatas(condition);

        //格式化数据
        sysLogs.stream().forEach(sysLog -> {
            sysLog.setSl02(sysCache.getSysUserByID(sysLog.getSl02()) == null ? "" :sysCache.getSysUserByID(sysLog.getSl02()).getSu01());
            sysLog.setSl03(HUtil.stringToDateStr(sysLog.getSl03(),"yyyyMMddHHmmss","yyyy-MM-dd HH:mm:ss"));
        });
        return sysLogs;
    }

    @Override
    public SysLog getData(Condition condition, int flag) {
        return null;
    }

    @Override
    public SysLog getData(SysLog sysLog, int flag) {
        return null;
    }
}
